//
// Created by HouEn on 2022/4/30.
//

#ifndef BALANCECAR_BSP_I2C_H
#define BALANCECAR_BSP_I2C_H
#include "stm32f1xx_hal.h"
#include "stdint.h"
#include "gpio.h"
extern GPIO_InitTypeDef GPIO_InitStruct;
/*! I2C引脚宏定义 */
#define I2C_SCL_PORT    GPIOB
#define I2C_SCL_PIN     GPIO_PIN_6
#define I2C_SDA_PORT    GPIOB
#define I2C_SDA_PIN     GPIO_PIN_7

/*! I2C基本操作宏定义 */

//#define SDA_IN()          {  GPIO_InitStruct.Pin = I2C_SDA_PIN;\
//                             GPIO_InitStruct.Mode = GPIO_MODE_INPUT;\
//                             GPIO_InitStruct.Pull = GPIO_NOPULL;\
//                             GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;\
//                             HAL_GPIO_Init(I2C_SDA_PORT, &GPIO_InitStruct);}
//
//#define SDA_OUT()         {GPIO_InitStruct.Pin = I2C_SDA_PIN;\
//                             GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;\
//                             GPIO_InitStruct.Pull = GPIO_PULLUP;\
//                             GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;\
//                             HAL_GPIO_Init(I2C_SDA_PORT, &GPIO_InitStruct);}


#define SCL_UP()          HAL_GPIO_WritePin(I2C_SCL_PORT,I2C_SCL_PIN,GPIO_PIN_SET)
#define SCL_DOWN()        HAL_GPIO_WritePin(I2C_SCL_PORT,I2C_SCL_PIN,GPIO_PIN_RESET)
#define SDA_UP()          HAL_GPIO_WritePin(I2C_SDA_PORT,I2C_SDA_PIN,GPIO_PIN_SET)
#define SDA_DOWN()        HAL_GPIO_WritePin(I2C_SDA_PORT,I2C_SDA_PIN,GPIO_PIN_RESET)
#define SDA_READ()        HAL_GPIO_ReadPin(I2C_SDA_PORT,I2C_SDA_PIN)
#define DELAY_For_MPU()           delay_us_For_MPU(1)

void delay_ms_For_MPU(uint32_t ms);
void delay_us_For_MPU(uint32_t us);
void I2C_Start_For_MPU();
void I2C_Stop_For_MPU();
void I2C_Send_ACK_For_MPU();
void I2C_Send_NACK_For_MPU();
uint8_t I2C_Wait_ACK_For_MPU();
void I2C_Send_Byte_For_MPU(uint8_t Byte);
uint8_t I2C_Receive_Byte_For_MPU(uint8_t  ack);
uint8_t I2C_Read_Bytes_For_MPU(uint8_t addr,uint8_t len,uint8_t *buf);
uint8_t I2C_Write_Bytes_For_MPU(uint8_t addr,uint8_t len,uint8_t *buf);
#endif //BALANCECAR_BSP_I2C_H
